package tote.services;

import java.io.Serializable;

/**
 * Encapsulates the criteria needed to perform a data search.
 */
public class SearchCriteria implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * The user-provided search criteria for finding records.
     */
    private String searchString = "";

    /**
     * The maximum page size of the result list
     */
    private int pageSize = 5;

    /**
     * The current page of the result list.
     */
    private int page;

    private String sortBy = null;

    public String getSortBy(String columns) {
	if (columns == null || columns.trim().length() == 0)
	    return getSortBy();
	return (sortBy == null || sortBy.trim().length() == 0) ? " order by " + columns : " order by " + columns + ","
		+ sortBy;
    }

    public String getSortBy() {
	return (sortBy == null || sortBy.trim().length() == 0) ? "" : " order by " + sortBy;
    }

    public void setSortBy(String sortBy) {
	this.sortBy = sortBy;
    }

    public String getSearchString() {
	return searchString;
    }

    public void setSearchString(String searchString) {
	this.searchString = searchString;
    }

    public int getPageSize() {
	return pageSize;
    }

    public void setPageSize(int pageSize) {
	this.pageSize = pageSize;
    }

    public int getPage() {
	return page;
    }

    public void setPage(int page) {
	this.page = page;
    }

    public void nextPage() {
	page++;
    }

    public void previousPage() {
	page--;
    }

    public void resetPage() {
	page = 0;
	sortBy = "name";
    }

    public String toString() {
	return "[Search Criteria searchString = '" + searchString + "'";
    }
}